#include "log.h"
#include "SEGGER_RTT.h"
#include "console.h"
#include <stdarg.h>


volatile uint8_t write_flag = 0;


void log_init(void)
{

#if (LOG_SELECT == RTT_LOG)
    SEGGER_RTT_Init();
#elif (LOG_SELECT == UART_LOG)
	LogInfertace_t tLogInfertace;

	tLogInfertace.send = usartLog;
	init_log(&tLogInfertace);
#endif

#if CONSOLE_ENABLE
    console_init();
#endif
}

#if (LOG_ENABLE_LEVEL > LOG_LEVEL_NONE)


void log_write(const char* format, ...)
{
	write_flag = 1;
    va_list arg;
    va_start(arg, format);
    SEGGER_RTT_vprintf(0, format, &arg);
    va_end(arg);
    write_flag = 0;
}

void log_buf(const char *buf, int len)
{
	write_flag = 1;
	SEGGER_RTT_printf_buf(0, buf, len);
	write_flag = 0;
}

#endif // LOG_ENABLE_LEVEL
